<template>
  <div class="container">
    <a-table class="table" :rowKey="row => row.id" :dataSource="list"  :pagination="pagination"
      :loading="loading"
      @change="onPaginationChange">
      <a-table-column title="用户ID" width="60px">
        <template slot-scope="row">
          <div>{{row.user_id}}</div>
        </template>
      </a-table-column>
      <a-table-column
        title="登陆用户"
        key="name"
        width="100px"
      >
        <template slot-scope="row">
          <span v-if="row.user">
            <img :src="row.user.headimg" class="headimg">
            {{ row.user.name }}
            <a-tag color="red" style="margin-left:10px;" v-if="row.user.status === 2">已拉黑</a-tag>
            <a-tag color="red" style="margin-left:10px;" v-if="row.user.is_nopay === 1">禁付</a-tag>
          </span>
        </template>
      </a-table-column>
      <a-table-column title="手机" width="60px">
        <template slot-scope="row">
          <div v-if="row.user">{{row.user.phone}}</div>
        </template>
      </a-table-column>
      <a-table-column title="成长等级" width="110px">
        <template slot-scope="row">
          <span>{{ row.task_level }}级</span>
        </template>
      </a-table-column>
      <a-table-column title="实付金额" width="100px">
        <template slot-scope="row">
          <NumberGroupDisplay :info="row" prefix="total_pay_"></NumberGroupDisplay>
        </template>
      </a-table-column>
      <a-table-column title="ip" width="80px">
        <template slot-scope="row">
          <div>{{row.ip}}</div>
        </template>
      </a-table-column>
      <a-table-column title="地区" width="60px">
        <template slot-scope="row">
          <div>{{ row.city || row.province }}</div>
        </template>
      </a-table-column>
      <a-table-column title="最后访问时间" width="60px">
        <template slot-scope="row">
          <div>{{row.visit_at | formatDate}}</div>
        </template>
      </a-table-column>
      
    </a-table>


  </div>
</template>

<script>
  import { getCitysearchList } from '@/api/visitors'
  import moment from 'moment'
  import NumberGroupDisplay from './NumberGroupDisplay'

  export default {
    components: {
      NumberGroupDisplay
    },
    data() {
      return {
        info: {},
        list: [],
        page: 1,
        per_page: 10,
        total: 0,
        pageSizeOptions: ['10', '20', '30', '40', '50'],
        loading: false,
      }
    },
    computed: {
      pagination () {
        return {
          defaultPageSize: this.per_page,
          defaultCurrent: this.page,
          total: this.total,
          pageSizeOptions: this.pageSizeOptions,
          showSizeChanger: true
        }
      }
    },
    props: {
      search_city: '',
      start_date: '',
    },
    created() {
      this.fetchData();
    },
    filters: {
      formatDate (value) {
        return value ? moment(value).fromNow() : ''
      },
      formatDate2 (value) {
        return value ? moment(value).format('YYYY-MM-DD') : ''
      }
    },
    mounted() {},
    watch: {},
    methods: {
       fetchData () {
         this.loading = true
        getCitysearchList({
          search_city:this.search_city,
          start_date:this.start_date,
          page: this.page,
          per_page: this.per_page
        }).then(res => {
          this.list = res.data.list
          this.total = res.data.item_total
          this.loading = false
        })
      },
      onPaginationChange (e) {
        this.page = e.current
        this.per_page = e.pageSize
        this.fetchData()
      },
      cancel() {
        this.$router.back(-1)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .headimg {
    width: 28px;
    height: 28px;
    border-radius: 50%;
  }


  .form-container {
    padding-bottom: 120px;
  }

  .container {
    .btn {
      margin-right: 30px;
    }
  }

  .tips-c {
    margin-bottom: 20px;
    font-weight: 500;
  }
</style>
